<!DOCTYPE html>
<html>
<head>
<#include "../common/head.ftl">
</head>
<body>
<div class="wrapper">
    <div class="section">
        <div class="search-wrapper clearfix">
            <div class="pull-left">
                <form class="form-inline" id="search_form">
                    <div class="form-group">
                        <input type="text" name="keywords" class="form-control" placeholder="请输入名称或标识" maxlength="20">
                        <input type="hidden" name="pid" class="form-control">
                    </div>
                    <button type="button" class="btn btn-default search-btn"><span class="fa fa-search"></span>&nbsp;查询</button>
                    <button type="reset" class="btn btn-default"><span class="fa fa-undo"></span>&nbsp;重置</button>
                </form>
            </div>
            <div class="pull-right">
                <button type="button" id="add_btn" class="btn btn-default"><span class="fa fa-plus"></span>&nbsp;新增</button>
            </div>
        </div>
        <div class="grid-wrapper">
            <table id="grid"></table>
            <div id="pager"></div>
        </div>
    </div>
</div>
<#include "../common/tab_oper.ftl">
</body>
<#include "../common/scripts.ftl">
<script type="text/javascript">
    var grid;
    grid = $("#grid").jqGrid({
        height: Public._win.gridBigHeight(),
        url: "sys_user/list/page",
        pager: "#pager",
        colModel: [
            {label:"操作",name:"ctrl",width:20,formatter:function(val,opt,obj){
                    var html = "<div class='operating'>";
                    html += "<@shiro.hasPermission name='sys_user:edit'><span class='fa fa-edit edit_btn' title='修改' data-id='"+obj.m.id+"'></span>&nbsp;&nbsp;</@shiro.hasPermission>";
                    html += "<@shiro.hasPermission name='sys_user:delete'><span class='fa fa-trash delete_btn' title='删除' data-id='"+obj.m.id+"'></span></@shiro.hasPermission>";
                    html += "</div>";
                    return html;
                }},
            {label:"ID",name:"m.id",key:true,hidden:true},
            {label:"名称",name:"m.name",width:40},
            {label:"账号",name:"m.account",width:20},
            {label:"邮箱",name:"m.email",width:20},
            {label:"最后登录IP",name:"m.lastLoginIp",width:20},
            {label:"最后登录时间",name:"m.lastLoginTime",width:20}
        ],
        loadComplete : function() {
            $(".edit_btn").on("click",function() {
                var id = $(this).data("id");
                layer.open({
                    type : 2,
                    maxmin:true,
                    title : "修改系统用户信息",
                    area : [ "768px", "220px" ],
                    content : "sys_user/edit/"+id
                });
            });
            $(".delete_btn").on("click",function(){
                var id = $(this).data("id");
                layer.confirm("确认删除该资源信息？", {
                    btn: ["确认","取消"]
                }, function(index,layero){
                    $(layero).find(".layui-layer-btn0").off("click");
                    var noCache = new Date().getTime();
                    $.getJSON("sys_user/delete/" + id,{"noCache":noCache}, function(data) {
                        layer.msg(data.message);
                        grid.jqGrid().trigger("reloadGrid");
                        tree.reAsyncChildNodes(null, "refresh");
                    });
                }, function(){});
            });
        },
        gridComplete : function() {
            setTimeout(function() {
                Public._grid.autoSize(grid);
            }, 10);
        }
    });
    $(".search-btn").on("click",function(){
        grid.jqGrid("setGridParam",{postData:$("#search_form").serializeObject(),page:1}).trigger("reloadGrid");
    });

    $("#add_btn").on("click",function(){
        layer.open({
            type : 2,
            title : "新增系统用户信息",
            area : [ "768px", "220px" ],
            content : "sys_user/add"
        });
    });
</script>
</html>